import { defineStore } from "pinia"
import { getSources } from "~/utils/sourcesUtil"

export const useSourceStore = defineStore('sourceStore', {
  state: () => {
    return {
      currentSourceIdx: 0, 
      sources: [] as SourceType[]
    }
  },
  actions: {
    setCurrentIdx(idx: number) {
      this.currentSourceIdx = idx 
    },
    async refreshSources() {
      return getSources().then(res => {
        this.sources = [...res]
      })
    },
    isSourcesEmpty() {
      return this.sources.length === 0
    }
  }
})